//1.引入express模块
const Koa = require('koa')
const Router = require('koa-router')

const bodyParser = require('koa-bodyparser')
const passport = require('koa-passport')
const cors = require('koa-cors')
const koaBody = require('koa-body')
const koaStatic = require('koa-static')
const path = require('path')

//2.创建express实例对象
var app = new Koa()
const router = new Router()

app.use(new bodyParser())
  
// 处理跨域
app.use(cors({origin: '*'}))

// app.use(koaBody({multipart: true}))


app.use(koaStatic(path.join(__dirname, './upload/')))

//连接mongodb数据库
require("./db/index.js")


var userRouter = require('./router/user')
//应用 用户的 子路由
router.use( "/api/user", userRouter )

// app.use(passport.initialize())
// app.use(passport.session())

require('./config/passport')(passport)
// 配置路由
app.use(router.routes()).use(router.allowedMethods())

//3.监听端口
app.listen(8888, () => {
    console.log('服务器运行在 http://localhost:8888');
})
